<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
     <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap-theme.min.css" integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ" crossorigin="anonymous">
    <style>
        .navbar {
            border-radius: 0;
                    }
    </style>
</head>

<body>
<!-- 固定访问的URL不变  -->
    <script>
    // 在页面加载时执行
    window.onload = function() {
        // 将浏览器的URL替换为固定的URL
        window.history.replaceState(null, null, '/admin/');
    };
    </script>
<div class="container">
    <div style="margin-bottom: 10px" class="clearfix">
        <div style="float: right;width: 500px">
            <form method="get">
                <div class="col-lg-6">
                    <div class="input-group">
                        <input type="text" name="q" class="form-control" placeholder="请输入IP或地区" value={{ search_data }}>
                        <span class="input-group-btn">
                        <button class="btn btn-default" type="submit">
                            <span class="glyphicon glyphicon-search" aria-hidden="true"></span>
                        </button>
                      </span>
                    </div><!-- /input-group -->
                  </div><!-- /.col-lg-6 -->
            </form>
        </div>
    </div>
    <div class="panel panel-default">
        <div class="panel-heading">
            <!--span class="glyphicon glyphicon-th-list" aria-hidden="true"></span-->
            <span>选择要备份配置的设备:</span>
        </div>
        <form method="POST">
            <table class="table table-bordered">
             {% csrf_token %}
              <thead>
                    <tr>
                        <th><input type="checkbox" id="button_all" name="device" value="{{ device.id }}"></th>
                        <th>管理IP</th>
                        <th>设备名称</th>
                        <th>地区</th>
                    </tr>
              </thead>
              <tbody>
                {% for device in devices %}
                    <tr>
                        <td><input type="checkbox" name="device" value="{{ device.id }}"></td>
                        <td>{{device.ip}}</td>
                        <td>{{device.dev_name}}</td>
                        <td>{{device.diqu}}</td>
                    </tr>
                {% endfor %}
             <tbody>
            </table>
        <button type="submit" class="mt-3 btn btn-primary">开始备份</button>
        </form>
    </div>
      <div class="clearfix">
        <ul class="pagination" style="float:left;">
            {{ page_string }}
            <li>
                <form method="get" style="float: left;margin-left: -1px">
                    <div class="input-group" style="width: 110px">
                        <input type="text" name="page" class="form-control" placeholder="页码">
                        <span class="input-group-btn">
                            <button type="submit" class="btn btn-default">跳转</button>
                        </span>
                    </div>
                </form>
            </li>

        </ul>
    </div>

</div>
<script>
    //1.获取元素
    var button_all = document.getElementById('button_all')
    var button_son = document.querySelector('tbody').getElementsByTagName('input')
<!--    console.log(button_all)-->
<!--    console.log(button_son)-->

    //2.注册事件
    button_all.onclick = function(){
        for (var i=0;i<button_son.length;i++){
            button_son[i].checked = this.checked
        }
    }

    //给每个小按钮绑定一个点击事件
    for (var i=0;i<button_son.length;i++){
        button_son[i].onclick = function(){
            var flag = true
            for (var j = 0;j<button_son.length;j++){
                if(!button_son[j].checked){
                    flag = false
                }
                button_all.checked = flag
            }
        }
    }
</script>

<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
</body>
</html>